/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * YearOptions.java
 * wholebasic
 * 2014年6月9日上午11:52:14
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.web.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.joda.time.DateTime;

public class YearOptions extends SimpleTagSupport {
   
    private int start = DateTime.now().getYear();
    private int end   = start+5;
        
    
    @Override
   	public void doTag() throws JspException, IOException {
    	JspContext jctx = getJspContext();
    	JspWriter jwriter = jctx.getOut(); 	
    	int n = DateTime.now().getYear();
    	if(end<start)end=start;    	
    	StringBuffer sb  =new StringBuffer();
    	for(int s = start;s<=end;s++){
    		String select = (s==n)?"selected":"";
    		sb.append(String.format("<option  value='%d' %s >%d</option>\n", s,s,select));
    	}
    	jwriter.write(sb.toString());
    	    	
    }
            
	public int getStart() {
		return start;
	}
	
	public int getEnd() {
		return end;
	}
	
	public void setStart(int start) {
		this.start = start;
	}
	
	public void setEnd(int end) {
		this.end = end;
	}

}
